package com.example.mall.client;

import com.example.mall.client.fallback.ProductFeignClientFactory;
import com.example.mall.result.JSONResult;
import feign.Request;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @Author: xxxliu
 * @CreateTime: 2025-06-03
 * @Version: 1.0
 */
@FeignClient(value = "mall-service-product",fallbackFactory = ProductFeignClientFactory.class,configuration = ProductFeignClient.FeignConfig.class)
@RequestMapping("/products")
public interface ProductFeignClient {

    @RequestMapping(value = "/info/json/{id}",method = RequestMethod.GET)
    JSONResult getProductInfo(@PathVariable("id")Long id);

    @RequestMapping(value = "/infos/json",method = RequestMethod.POST)
    JSONResult getProductInfos(@RequestBody List<Long> productIds);

    @Configuration
    public class FeignConfig {
        @Bean
        public Request.Options options() {
            return new Request.Options(10000, 60000); // 设置连接和读取超时时间
        }
    }
}
